package mysql

import (
	"gorm.io/gorm"
	"hippofresh/hippofreshrpc/hippofreshrpc"
)

type HippoFresh struct {
	gorm.Model
	Title   string  `gorm:"type:varchar(30);comment:标题"`
	Name    string  `gorm:"type:varchar(30);comment:名称"`
	Price   float64 `gorm:"type:decimal(10,2);comment:价格"`
	TyperId int     `gorm:"type:int;comment:类型ID"`
}

func (f *HippoFresh) HippoFresh(db *gorm.DB) error {
	return db.Debug().Create(&f).Error
}

func (f *HippoFresh) FindTitle(db *gorm.DB, title string) error {
	return db.Debug().Where("title=?", title).First(&f).Error
}
func HippoList(db *gorm.DB, in *hippofreshrpc.HippoFreshListRequest) ([]*hippofreshrpc.HippoFreshList, error) {
	var list []*hippofreshrpc.HippoFreshList
	err2 := db.Debug().Model(&HippoFresh{}).Select(
		"id",
		"title",
		"name",
		"price",
		"typer",
	).Scopes(Paginate(int(in.Page), int(in.Size))).Find(&list).Error
	return list, err2
}
